﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using System.Data;

namespace University.Workshop.DataAccess
{
    public static class TreatmentDataAccess
    {
        public static bool InsertNewTreatment(Treatment treatment, GeneralTreatment generalTreatment, ToothTreatment toothTreatment)
        {
            if (treatment != null && generalTreatment !=null && toothTreatment!=null)
            {
                string stringConnection = "insert into Treatment(IdTreatment,StateTreatment,Diagnostic_IdDiagnostic)values('"+treatment.CodeTreatment+"','"+treatment.State+"','"+treatment.CodeDiagnostic+"')";
                if (ExecuteConsult(stringConnection))
                {
                    string strinConnectionGeneral = "insert into GeneralTreatment(NameTreatment,Description,Treatment_IdTreatment)values('" + generalTreatment.Treatment + "','" + generalTreatment.Description + "'," + generalTreatment.CodeTreatment + ")";
                    if (ExecuteConsult(strinConnectionGeneral))
                    {
                        string strinConnectionTooht = "insert into ToothTreatment(NamberTooth,TypeTooth,LocationTooth,NameTreatment,Description,ImageTooth,Treatment_IdTreatment)values(" + toothTreatment.ToothCode + ",'" + toothTreatment.ToothType + "','" + toothTreatment.ToothLocation + "','" + toothTreatment.Treatment + "','" + toothTreatment.TreatmentDescription + "','" + toothTreatment.ToothImage + "'," + toothTreatment.CodeTreatment + ")";
                        return ExecuteConsult(strinConnectionTooht);
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        private static bool ExecuteConsult(string stringConnection)
        {
            using (DBConnection connection = new DBConnection())
            {
                if (connection.CommandExecuteConsult(stringConnection))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


        public static DataTable LoadDataTreatmentOfTheSelectedAppointment()
        {
            string stringConnection = "select * from Patient";//Edit this line!!!!!
            using (DBConnection connection = new DBConnection())
            {
                return connection.ConsultationSelectDataTable(stringConnection);
            }

        }
    }
}
